using System;
using System.Collections.Generic;
using System.Text;
using Enyim.Caching.Memcached;
using AgileJedi.Core.Serialization;

namespace AgileJedi.MemcachedForMonorail.Transcoders
{
	public class FastSerializerTranscoder : ITranscoder
	{
		#region ITranscoder Members

		public object Deserialize(CacheItem item)
		{
			SerializationReader reader = new SerializationReader(item.Data.Array);
			object returnObject = reader.ReadObject();
			return returnObject;
		}

		public CacheItem Serialize(object o)
		{
			CacheItem cacheitem = new CacheItem();
			SerializationWriter writer = new SerializationWriter();

			writer.OptimizeForSize = false;
				writer.WriteObject(o);
			
			cacheitem.Data = new ArraySegment<byte>(writer.ToArray());
			
			return cacheitem;
			
		}

		#endregion
	}
}
